package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection();
        ) {
            Statement statement = connection.createStatement();
            String sql = "SELECT COUNT(*) '人数' " +
                    "FROM class c " +
                    "JOIN student s ON c.id = s.class_id " +
                    "WHERE C.name='1年级1班'";
            ResultSet rs = statement.executeQuery(sql);
            if (rs.next()) {
                int count = rs.getInt("人数");
                System.out.println("一共有" + count + "人");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
